@isTest
private class ProductOutOrInSycControllerTest {
    static testMethod void testMethod1() {

    	Account acc = TestUtils.createAccount();
    	acc.AccountNumber = '111234';
        insert acc;

        ProductStructure__c ps = new ProductStructure__c();
        ps.Classify3__c = '试剂';
        insert ps;
        Product__c p1 = TestUtils.createProduct();
        p1.Category0__c = '试剂';
        p1.ProductStructure__c = ps.Id;
        p1.NCCode__c = '12345567';
        insert p1;

         Product__c p2 = TestUtils.createProduct();
        p2.Category0__c = '试剂';
        p2.ProductStructure__c = ps.Id;
        p2.NCCode__c = '12345566';
        insert p2;

        ProductOutOrIn__c poi = new ProductOutOrIn__c();
        poi.BorrowType__c= '未定价先发货';
        poi.Status__c = '草案中';
        poi.Customer__c = acc.Id;
        insert poi ; 

        BorrowGoodsDetail__c bg  = new BorrowGoodsDetail__c();
        bg.Inventory__c =p1.Id;
        bg.BorrowDetail__c = poi.Id;
        insert bg;

        BorrowGoodsDetail__c bg1  = new BorrowGoodsDetail__c();
        bg1.Inventory__c =p2.Id;
        bg1.BorrowDetail__c = poi.Id;
        insert bg1;

         PageReference page = new PageReference('/apex/ProductOutOrIn?id=' + poi.Id );
        System.Test.setCurrentPage(page);
        ProductOutOrInSycController poic = new ProductOutOrInSycController();

        poic.init();
        poic.getJmcode();
        Map<String,Object> sMap = new Map<String,Object>();
        sMap.put('jmcode', '01');
        sMap.put('jmname', 'xxx');
        sMap.put('corpcode', 'MKSW');
        
        sMap.put('noprice', new List<String>{'12345566'});
        poic.syncJson = EncodingUtil.urlEncode(JSON.serialize(sMap), 'UTF-8') ;
        poic.sync();
        Map<String,String> searchMap = new Map<String,String>();
        searchMap.put('NCCod', '12345567');
        poic.resJson = EncodingUtil.urlEncode(JSON.serialize(searchMap), 'UTF-8') ;
        poic.search();

        List<ProductOutOrInSycController.BrorrowBean> tmp = new List<ProductOutOrInSycController.BrorrowBean>();
        tmp.add(new ProductOutOrInSycController.BrorrowBean(bg));

        poic.saveJson =EncodingUtil.urlEncode(JSON.serialize(tmp), 'UTF-8') ;
        poic.save();

                poi.Status__c = '已批准';
                update poi;

         PageReference page1 = new PageReference('/apex/ProductOutOrIn?id=' + poi.Id +'&syc=true');
        System.Test.setCurrentPage(page1);
        ProductOutOrInSycController poic1 = new ProductOutOrInSycController();
        poic1.init();



        
    }
}